<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>微博构造</title>
</head>

<body>
<?php
print_r($_REQUEST);
	include ("/class/chineseDate.php");//农历,节日
	include("/class/class.xml.parser.php");//天气
include("/class/class.weather.php");//天气
	$today = date("Y-m-d");
	$chineseDate = new chineseDate();
	
	$gl = date("Y")."年".date("m")."月".date("d")."日";
	echo "今天公历是:$gl<br/>";
	//公历转农历
	$nl = $chineseDate->CS2L($today);
	echo "转为农历是:$nl<br/>";
	$nl = substr ($nl,15);
	echo "整理农历是:$nl<br/>";
	$jr = $chineseDate->JR($today);
	echo "今天节日是:$jr<br/>";
	//week
	$weekarray=array("日","一","二","三","四","五","六");  
    $week=$weekarray[date("w",$today)];
	
	/*weather */
	
$timeout=3*60*60;  // 3 hours
if (isset($_ENV["TEMP"]))
  $cachedir=$_ENV["TEMP"];
else if (isset($_ENV["TMP"]))
  $cachedir=$_ENV["TMP"];
else if (isset($_ENV["TMPDIR"]))
  $cachedir=$_ENV["TMPDIR"];
else
// Default Cache Directory  
  $cachedir="/tmp";
  
$cachedir=str_replace('\\\\','/',$cachedir);
if (substr($cachedir,-1)!='/') $cachedir.='/';

$weather_chile = new weather("12761782", 3600, "c", $cachedir);
$weather_chile->parsecached();
//for ($day=0; isset($weather_chile->forecast[$day]); $day++) {
	$day = 0;
  print "<h1>Forecast Day $day</h1>";
  //print_r($weather_chile->forecast[$day]);
  print "day: ".$weather_chile->forecast[$day]['DAY']."<br>"; 
  print "date: ".$weather_chile->forecast[$day]['DATE']."<br>";    // 26 Oct 2005
  print "lowest: ".$weather_chile->forecast[$day]['LOW']."<br>";   // 8
   $weather_lowest = $weather_chile->forecast[$day]['LOW'];
  print "highest: ".$weather_chile->forecast[$day]['HIGH']."<br>"; // 19
  $weather_highest = $weather_chile->forecast[$day]['HIGH'];
  print "text: ".$weather_chile->forecast[$day]['TEXT']."<br>";    // Partly Cloudy
  $weather_text = $weather_chile->forecast[$day]['TEXT']; //需要转换到中文
  
  print "<hr>";
//}
?>

<?php
if($_REQUEST != NULL)
{
	$weibo = $_REQUEST[text].$_REQUEST[weathermore].$_REQUEST[moretext].$_REQUEST[custommoretext]."      	www.SJUCSSA.com";
	?>
	微博内容(<a href="post.php?text=<?=$weibo?>">发送</a>): <font color="#FF0000">
	<?php
	echo $weibo;
	echo "</font>";
	}
?>


<form action="">
 
  <textarea name="text" cols="50" rows="10" id="text"><?php 
  echo "今天是公元".$gl.$week."，农历".$nl;
  if($jr != NULL)
  echo "，今天是".$jr."，祝大家节日快乐!";
  else
  echo "。";
  echo "今天最高温度".$weather_highest."度，最低温度".$weather_lowest."度,";
  text2cn($weather_text);
  echo "。";
  
  ?>
  </textarea><br/>
<p>
天气附加(单选):<br/>
  <label>
    <input type="radio" name="weathermore" value="出门记得带雨具！" id="weathermore_0">
    出门记得带雨具！</label>
  <br>
  <label>
    <input type="radio" name="weathermore" value="气温偏低，出门要注意保暖！" id="weathermore_1">
    气温偏低，出门要注意保暖！</label>
  <br>
  <label>
    <input type="radio" name="weathermore" value="气温开始回暖了哦！" id="weathermore_2">
    气温开始回暖了哦！</label>
  <br>
  <label>
    <input type="radio" name="weathermore" value="天热注意避暑哦！" id="weathermore_3">
    天热注意避暑哦！</label>
  <br>
</p>
<p>
常用语句1(多选):<br/>
  <label>
    <input type="radio" name="moretext" value="今天是" id="moretext_0">
    今天是</label>
  <br>
  <label>
    <input type="radio" name="moretext" value="明天是" id="moretext_1">
    明天是</label>
     <br>
     <input type="radio" name="moretext" value="今晚" id="moretext_2">
    今晚</label>
     <br>
     <input type="radio" name="moretext" value="明晚" id="moretext_3">
    明晚</label>
  <br>
  自定义:
  <br/>
  <textarea name="custommoretext" cols="50" rows="10" id="text"></textarea>
  <br/>
<input type="submit"  value="预览"/>
</form>
<?php
//function
function text2cn($text){
switch($text)
{
	case "Drizzle":
	echo "细雨";
	break;
	case "Showers":
	echo "阵雨";
	break;
	case "AM Showers":
	echo "早上阵雨";
	break;
	case "PM Showers":
	echo "下午阵雨";
	break;
	case "Cloudy":
	echo "多云";
	break;
	case "Partly Cloudy":
	echo "局部多云";
	break;
	case "Mostly Cloudy":
	echo "多云为主";
	break;
	case "Partly Sunny":
	echo "局云以晴";
	break;
	case "Mostly Sunny":
	echo "以晴为主";
	break;
	default:
	echo "天气未知";
	break;
	}
}
?>
</body>
</html>
